#include "mylist.h"


struct MyListHead *CreateMyListHead()
{
	struct MyListHead *pstHead = NULL;
	
	pstHead = (struct MyListHead *)malloc(sizeof(struct MyListHead));
	if(NULL == pstHead)
	{
		printf("Malloc Failed in %s at %d\n",__FILE__,__LINE__);
		return NULL;
	}
	memset(pstHead,0,sizeof(struct MyListHead));
	
	return pstHead;
}

struct MyListNode *CreateMyListNode(struct NodeData* pstNewData)
{
	struct MyListNode *pstNode = NULL;
	
	pstNode = (struct MyListNode *)malloc(sizeof(struct MyListNode));
	if(NULL == pstNode)
	{
		printf("Malloc Failed in %s at %d\n",__FILE__,__LINE__);
		return NULL;
	}
	memset(pstNode,0,sizeof(struct MyListNode));

	//pstNode->data.a = pstNewData->a;
	//pstNode->data.b = pstNewData->b;
	
	memcpy(&pstNode->data,pstNewData,sizeof(struct NodeData));
	//处理指针成员指向空间的数据
	
	return pstNode;
}

int DestroyMyListNode(struct MyListNode *pstNode)
{
	if(pstNode != NULL)
	{
		free(pstNode);
	}
	
	return 0;
}

int DestroyMyListHead(struct MyListHead *pstHead)
{
	struct MyListNode *pstNode = NULL;
	struct MyListNode *pstNext = NULL;
	
	if(pstHead == NULL)
	{
		printf("Input param is error in %s at %d\n",__FILE__,__LINE__);
		return 1;
	}
	
	pstNode = pstHead->pstFirst;
	while(pstNode != NULL)
	{
		pstNext = pstNode->pstNext;
		DestroyMyListNode(pstNode);
		pstNode = pstNext;
	}
	
	free(pstHead);	
	return 0;
}
